package com.chenl.provider.util.ScanUtils;

import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.stereotype.Component;

@Component
public class InterfaceScanner extends ClassPathScanningCandidateComponentProvider {

    public InterfaceScanner() {
        super(false);
    }

    @Override
    protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
        return beanDefinition.getMetadata().isInterface() && beanDefinition.getMetadata().isIndependent();
    }


    // 示例用法
    public static void main(String[] args) {
        InterfaceScanner scanner = new InterfaceScanner();
        scanner.addIncludeFilter(new AnnotationTypeFilter(FeignClient.class));
        for (BeanDefinition beanDef : scanner.findCandidateComponents("packageName")) {
            // 处理找到的接口
        }
    }
}